package org.freemarker.core.service.impl;

import org.freemarker.core.dao.ContactDao;
import org.freemarker.core.dao.EntityJpaDao;
import org.freemarker.core.dto.GenderStatistics;
import org.freemarker.core.model.Contact;
import org.freemarker.core.model.Gender;
import org.freemarker.core.service.ContactService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service
public class ContactServiceImpl extends BaseServiceImpl<Contact> implements
		ContactService {

	private static final Logger logger = LoggerFactory
			.getLogger(ContactServiceImpl.class);

	@Autowired
	@Qualifier("contactDaoImpl")
	public void setEntityJpaDao(EntityJpaDao<Contact> entityJpaDao) {
		this.entityJpaDao = entityJpaDao;
	}

	@Override
	public GenderStatistics getContactCountOnGender(Gender g) {
		GenderStatistics gs = null;

		if (Gender.MALE.toString().equals(g.name())) {
			gs = new GenderStatistics(Gender.MALE,
					((ContactDao) entityJpaDao)
							.getDaoContactCountOnGender(Gender.MALE));
		} else {
			gs = new GenderStatistics(Gender.FEMALE,
					((ContactDao) entityJpaDao)
							.getDaoContactCountOnGender(Gender.FEMALE));
		}
		return gs;
	}

	@Override
	public Contact getContactBySecurityNumber(String securityNumber) {
		return ((ContactDao)entityJpaDao).getContactBySecurityNumber(securityNumber);
	}
	
	@Override
	public void updateContactBySecurityNumber(Contact c) {
		((ContactDao)entityJpaDao).updateBySecurityNumber(c);
	}


}
